package com.emaimed.search.controller;

import com.emaimed.search.es.SmsDataEs;
import com.emaimed.search.pojo.PageInfo;
import com.emaimed.search.pojo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.io.IOException;
import java.util.Map;

/**
 * @author Fafa Tuo
 * @version 1.0
 * @date 2021/6/24 22:31
 */

@Controller
@RequestMapping(value = "/smsEs")
public class EmaimedSmsEsController {

    @Autowired
    private SmsDataEs smsDataEs;

    @RequestMapping(value = "/getSendNumber")
    @ResponseBody
    public Result<Map<String,Object>> getSendNumbers(PageInfo pageInfo,
                                                     @RequestParam("param") String param){

        System.out.println("pageSize==== "+pageInfo.getPageSize());
        System.out.println("currentPage==== "+pageInfo.getCurrentPage());
        System.out.println("param = " + param);
        Result<Map<String,Object>> result = new Result<Map<String,Object>>();
        try {
            Map<String, Object> sendNumbers;
            if(param.equals("all")){
                sendNumbers = smsDataEs.getEmaimedSmsAll(pageInfo);
            }else {
                sendNumbers = smsDataEs.getSendNumbers(pageInfo,param);
            }
            result.setCode(200);
            result.setMsg("success");
            result.setData(sendNumbers);
            return result;
        } catch (IOException e) {
            e.printStackTrace();
            result.setCode(800);
            result.setMsg("false");
            return result;
        }

    }

    @RequestMapping(value = "/getReceiveNumber")
    @ResponseBody
    public Result<Map<String,Object>> getReceiveNumber(PageInfo pageInfo,
                                                       @RequestParam("param") String param){

        System.out.println("pageSize==== "+pageInfo.getPageSize());
        System.out.println("currentPage==== "+pageInfo.getCurrentPage());
        System.out.println("param = " + param);
        Result<Map<String,Object>> result = new Result<Map<String,Object>>();
        try {
            Map<String, Object> sendNumbers;
            if(param.equals("all")){
                sendNumbers = smsDataEs.getEmaimedSmsAll(pageInfo);
            }else {
                sendNumbers = smsDataEs.getReceiveNumber(pageInfo, param);
            }
            result.setCode(200);
            result.setMsg("success");
            result.setData(sendNumbers);
            return result;
        } catch (IOException e) {
            e.printStackTrace();
            result.setCode(800);
            result.setMsg("false");
            return result;
        }
    }


    @RequestMapping(value = "/getMsgContent")
    @ResponseBody
    public Result<Map<String,Object>> getMsgContent(PageInfo pageInfo,
                                                    @RequestParam("param") String param){
        System.out.println("pageSize==== "+pageInfo.getPageSize());
        System.out.println("currentPage==== "+pageInfo.getCurrentPage());
        System.out.println("param = " + param);
        Result<Map<String,Object>> result = new Result<Map<String,Object>>();
        try {
            Map<String, Object> sendNumbers;
            if(param.equals("all")){
                sendNumbers = smsDataEs.getEmaimedSmsAll(pageInfo);
            }else {
                sendNumbers = smsDataEs.getContent(pageInfo, param);
            }
            result.setCode(200);
            result.setMsg("success");
            result.setData(sendNumbers);
            return result;
        } catch (IOException e) {
            e.printStackTrace();
            result.setCode(800);
            result.setMsg("false");
            return result;
        }
    }

}
